package book.ch2.ArrayTest;

public class ArrayTest {

	public static void main(String[] args) {
		int[] aaa={23,14,35,2,71,55,82,41,11,6};
		Ary ay1=new Ary(aaa);
		ay1.print();
		ay1.order();
		ay1.print();
		for(int m=0;m<aaa.length;m++)
			System.out.print("---"+aaa[m]);
		System.out.println();
		Ary ay2=new Ary(ay1.subAry(2, 6));
		ay2.print();
	}

}
class Ary{
	int[] m_ary;
	Ary(int[] p){
		m_ary=p;
	}
	void print(){
		for(int i=0;i<m_ary.length;i++)
			System.out.print(m_ary[i]+" ");
		System.out.println();
	}
	void order(){
		int j,temp;
		boolean exchange = true;
		j=m_ary.length - 2;
		while(j>=0&&exchange){
			exchange=false;
			for(int i=0;i<=j;i++){
				exchange=true;
				temp=m_ary[i];
				m_ary[i]=m_ary[i+1];
				m_ary[i+1]=temp;
			}
			j=j-1;
			}
		}
	int[] subAry(int a1,int a2){
		int[] sa;
		if(a1>=0&&a1<a2&&a2<m_ary.length){
			sa=new int[a2-a1+1];
			for(int i=0,j=a1;j<=a2;i++,j++)
				sa[i]=m_ary[i];
			return sa;
		}
		else{
			System.out.println("error index");
			return new int[1];
		}
	}
}
